package com.example.baiduai.hander.impl;

import com.example.baiduai.dto.AiDto;
import com.example.baiduai.exception.PlatformException;
import com.example.baiduai.hander.PayMannerHander;
import com.example.baiduai.interfaces.Constat;
import com.example.baiduai.utils.GooGleCacheUtils;
import com.example.baiduai.utils.ObjectUtils;
import javafx.print.PageLayout;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 扫码支付  1
 */
@Component
public class ScanPayImpl extends PayMannerHander implements InitializingBean {

    @Autowired
    private CashPayImpl cashPay;

    @Override
    public String  payMannerStatus(AiDto dto) {
        if(ObjectUtils.isEmpty(dto.getLabelNames())) throw  new PlatformException("标签数组为空");
        if(dto.getLabelNames().contains("扫码支付")){
            Boolean b = GooGleCacheUtils.isewmPayCache(Constat.prefix.SCAN_PAY_PREFIX + dto.getDevice_id());

            // 没有值的时候是  第一次扫码支付
            if(ObjectUtils.isEmpty(b)){ //扫码支付
                // 加入缓存
                GooGleCacheUtils.ewmPayCachePut(Constat.prefix.SCAN_PAY_PREFIX + dto.getDevice_id());


                return "扫码支付加入缓存成功";
            }else return "扫码支付还在进行中"; // 扫码支付还在进行中

        }else return cashPay.payMannerStatus(dto);


    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.setPayHander(cashPay);
    }
}
